home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / SwingSet / ButtonPanel.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  9.6 KB  |  291 lines

  1. /*
  2.  * @(#)ButtonPanel.java    1.10 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import javax.swing.*;
  16. import javax.swing.border.*;
  17. import javax.swing.event.*;
  18. import javax.swing.text.*;
  19.  
  20. import java.awt.*;
  21. import java.awt.event.*;
  22. import java.util.*;
  23.  
  24.  
  25. /**
  26.  * Buttons!
  27.  *
  28.  * @version 1.10 08/26/98
  29.  * @author Jeff Dinkins
  30.  */
  31. public class ButtonPanel extends JPanel 
  32. {
  33.  
  34.     // The Frame
  35.     SwingSet swing;
  36.  
  37.     ImageIcon left = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/left.gif","fancy green arrow pointing left");
  38.     ImageIcon leftDown = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/leftDown.gif","fancy yellow arrow pointing left");
  39.     ImageIcon leftRollover = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/leftRollover.gif","fancy purple arrow pointing left");
  40.     ImageIcon right = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/right.gif","fancy green arrow pointing right");
  41.     ImageIcon rightDown = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/rightDown.gif","fancy yellow arrow pointing right");
  42.     ImageIcon rightRollover = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/rightRollover.gif","fancy purple arrow pointing right");
  43.  
  44.     public ButtonPanel(SwingSet swing) {
  45.     this.swing = swing;
  46.  
  47.     setBorder(swing.emptyBorder5);
  48.     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  49.  
  50.     // *************** buttons ****************
  51.     // text buttons
  52.     JPanel textButtons = SwingSet.createHorizontalPanel(false);
  53.     textButtons.setAlignmentX(LEFT_ALIGNMENT);
  54.     Border buttonBorder = new TitledBorder(null, "Text Buttons", 
  55.                            TitledBorder.LEFT, TitledBorder.TOP,
  56.                            swing.boldFont);
  57.  
  58.     Border emptyBorder = new EmptyBorder(5,5,5,5);
  59.     Border compoundBorder = new CompoundBorder( buttonBorder, emptyBorder);
  60.  
  61.     textButtons.setBorder(compoundBorder);
  62.  
  63.     JButton button;
  64.     button = new JButton("One");
  65.     button.setToolTipText("This is a Button with Text");
  66.         button.setMnemonic('o');
  67.     swing.buttons.addElement(button);
  68.     textButtons.add(button);
  69.     textButtons.add(Box.createRigidArea(swing.hpad10));
  70.     
  71.     button = new JButton("Two");
  72.     button.setToolTipText("This is a Button with Text");
  73.         button.setMnemonic('t');
  74.     swing.buttons.addElement(button);
  75.     textButtons.add(button);
  76.     textButtons.add(Box.createRigidArea(swing.hpad10));
  77.  
  78.     button = new JButton("Three");
  79.     button.setBackground(new Color(204, 204, 255));
  80.     button.setToolTipText("This is a Button with the background color set to be lavender");
  81.         button.setMnemonic('h');
  82.     swing.buttons.addElement(button);
  83.     textButtons.add(button);
  84.  
  85.  
  86.     // image buttons
  87.     JPanel imageButtons = swing.createHorizontalPanel(false);
  88.     imageButtons.setAlignmentX(LEFT_ALIGNMENT);
  89.  
  90.     buttonBorder = new TitledBorder(null, "Image Buttons", 
  91.                            TitledBorder.LEFT, TitledBorder.TOP,
  92.                            swing.boldFont);
  93.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  94.     imageButtons.setBorder(compoundBorder);
  95.  
  96.     // 1 image
  97.     button = new JButton(swing.upButton);
  98.     button.setToolTipText("This is a Button with a Icon");
  99.     button.getAccessibleContext().setAccessibleName("Right");
  100.     // button.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);
  101.     swing.buttons.addElement(button);
  102.     imageButtons.add(button);
  103.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  104.     
  105.     // 2 images
  106.     button = new JButton(swing.upButton);
  107.     button.setToolTipText("This is a Button with a Icon and a PressedIcon");
  108.     button.getAccessibleContext().setAccessibleName("Right");
  109.     swing.buttons.addElement(button);
  110.     button.setPressedIcon(swing.downButton);
  111.     imageButtons.add(button);
  112.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  113.  
  114.     // 3 images
  115.     button = new JButton(swing.upButton);
  116.     button.setToolTipText("This is a Button with a Icon, PressedIcon, and DisabledIcon");
  117.     button.getAccessibleContext().setAccessibleName("Right");
  118.     button.setPressedIcon(swing.downButton);
  119.     button.setDisabledIcon(swing.disabledButton);
  120.     swing.buttons.addElement(button);
  121.     imageButtons.add(button);
  122.  
  123.     // text&image buttons
  124.     JPanel tiButtons = swing.createHorizontalPanel(false);
  125.     tiButtons.setAlignmentX(LEFT_ALIGNMENT);
  126.     buttonBorder = new TitledBorder(null, "Rollover Image Buttons", 
  127.                            TitledBorder.LEFT, TitledBorder.TOP,
  128.                            swing.boldFont);
  129.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  130.     tiButtons.setBorder(compoundBorder);
  131.  
  132.     button = new JButton("Left", left);
  133.     button.setPressedIcon(leftDown);
  134.     button.setRolloverIcon(leftRollover);
  135.     button.setRolloverEnabled(true);
  136.     button.setToolTipText("This is a Button with a RolloverIcon");
  137.     swing.buttons.addElement(button);
  138.     tiButtons.add(button);
  139.     tiButtons.add(Box.createRigidArea(swing.hpad10));
  140.  
  141.     button = new JButton("Right", right);
  142.     button.setPressedIcon(rightDown);
  143.     button.setRolloverIcon(rightRollover);
  144.     button.setRolloverEnabled(true);
  145.     button.setToolTipText("This is a Button with a Rollover Icon");
  146.     swing.buttons.addElement(button);
  147.     tiButtons.add(button);
  148.     tiButtons.add(Box.createHorizontalBox());
  149.  
  150.     // Add button panels to buttonPanel
  151.     JPanel buttonPanel = swing.createVerticalPanel(true);
  152.     buttonPanel.setAlignmentX(LEFT_ALIGNMENT);
  153.     buttonPanel.setAlignmentY(TOP_ALIGNMENT);
  154.  
  155.  
  156.     buttonPanel.add(textButtons);
  157.  
  158.     buttonPanel.add(Box.createVerticalStrut(10));
  159.  
  160.  
  161.     buttonPanel.add(imageButtons);
  162.  
  163.     buttonPanel.add(Box.createVerticalStrut(10));
  164.  
  165.     buttonPanel.add(tiButtons);
  166.     buttonPanel.add(tiButtons);
  167.     buttonPanel.add(Box.createGlue());
  168.  
  169.  
  170.     // *************** Create the button controls ****************
  171.     JPanel controls = new JPanel() {
  172.         public Dimension getMaximumSize() {
  173.         return new Dimension(300, super.getMaximumSize().height);
  174.         }
  175.     };
  176.     controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS));
  177.     controls.setAlignmentY(TOP_ALIGNMENT);
  178.     controls.setAlignmentX(LEFT_ALIGNMENT);
  179.  
  180.     JPanel buttonControls = swing.createHorizontalPanel(true);
  181.     buttonControls.setAlignmentY(TOP_ALIGNMENT);
  182.     buttonControls.setAlignmentX(LEFT_ALIGNMENT);
  183.  
  184.     JPanel leftColumn = swing.createVerticalPanel(false);
  185.     leftColumn.setAlignmentX(LEFT_ALIGNMENT);
  186.     leftColumn.setAlignmentY(TOP_ALIGNMENT);
  187.  
  188.     JPanel rightColumn = swing.createVerticalPanel(false);
  189.     rightColumn.setAlignmentX(LEFT_ALIGNMENT);
  190.     rightColumn.setAlignmentY(TOP_ALIGNMENT);
  191.  
  192.     buttonControls.add(leftColumn);
  193.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  194.     buttonControls.add(rightColumn);
  195.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  196.  
  197.     controls.add(buttonControls);
  198.  
  199.        
  200.     // Display Options
  201.     JLabel l = new JLabel("Display Options:");
  202.     leftColumn.add(l);
  203.     l.setFont(swing.boldFont);
  204.  
  205.      JCheckBox bordered = new JCheckBox("Paint Border");
  206.     bordered.setToolTipText("Click here to turn border painting on or off.");
  207.         bordered.setMnemonic('b');
  208.      bordered.setSelected(true);
  209.      bordered.addItemListener(swing.buttonDisplayListener);
  210.      leftColumn.add(bordered);
  211.  
  212.      JCheckBox focused = new JCheckBox("Paint Focus");
  213.     focused.setToolTipText("Click here to turn focus painting on or off.");
  214.         focused.setMnemonic('f');
  215.      focused.setSelected(true);
  216.      focused.addItemListener(swing.buttonDisplayListener);
  217.      leftColumn.add(focused);
  218.  
  219.     JCheckBox enabled = new JCheckBox("Enabled");
  220.     enabled.setToolTipText("Click here to enable or disable the buttons.");
  221.     enabled.setSelected(true);
  222.         enabled.setMnemonic('e');
  223.     enabled.addItemListener(swing.buttonDisplayListener);
  224.     leftColumn.add(enabled);
  225.  
  226.     JCheckBox filled = new JCheckBox("Content Filled");
  227.     filled.setToolTipText("Click here to control the filling of the content area.");
  228.     filled.setSelected(true);
  229.         filled.setMnemonic('i');
  230.     filled.addItemListener(swing.buttonDisplayListener);
  231.     leftColumn.add(filled);
  232.  
  233.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  234.     
  235.     l = new JLabel("Pad Amount:");
  236.     leftColumn.add(l);
  237.     l.setFont(swing.boldFont);
  238.     
  239.     ButtonGroup group = new ButtonGroup();
  240.     JRadioButton defaultPad = new JRadioButton("Default");
  241.     defaultPad.setToolTipText("Uses the default padding between the border and label.");
  242.         defaultPad.setMnemonic('d');
  243.     group.add(defaultPad);
  244.     defaultPad.setSelected(true);
  245.      defaultPad.addItemListener(swing.buttonPadListener);
  246.     leftColumn.add(defaultPad);
  247.  
  248.     JRadioButton zeroPad = new JRadioButton("0");
  249.     zeroPad.setToolTipText("Uses no padding between the border and label.");
  250.         zeroPad.setMnemonic('0');
  251.     group.add(zeroPad);
  252.      zeroPad.addItemListener(swing.buttonPadListener);
  253.     leftColumn.add(zeroPad);
  254.  
  255.     JRadioButton tenPad = new JRadioButton("10");
  256.         tenPad.setMnemonic('1');
  257.     tenPad.setToolTipText("Uses a 10 pixel pad between the border and label.");
  258.     group.add(tenPad);
  259.      tenPad.addItemListener(swing.buttonPadListener);
  260.     leftColumn.add(tenPad);
  261.  
  262.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  263.  
  264.  
  265.     // *************** Create the layout controls ****************
  266.     // Create Text Position and Alignment Layout controls
  267.     JPanel textPosition = DirectionButton.createDirectionPanel(true, "E", swing.textPositionListener);
  268.     JPanel labelAlignment = DirectionButton.createDirectionPanel(true, "C", swing.labelAlignmentListener);
  269.  
  270.     l = new JLabel("Text Position:");
  271.     rightColumn.add(l);
  272.     l.setFont(swing.boldFont);
  273.      rightColumn.add(textPosition);
  274.  
  275.      rightColumn.add(Box.createRigidArea(swing.vpad20));
  276.  
  277.     l = new JLabel("Content Alignment:");
  278.     rightColumn.add(l);
  279.     l.setFont(swing.boldFont);
  280.      rightColumn.add(labelAlignment);
  281.  
  282.      rightColumn.add(Box.createGlue());
  283.  
  284.     add(buttonPanel);
  285.     add(Box.createRigidArea(swing.hpad10));
  286.      add(controls);
  287.     }
  288.  
  289.     
  290. }
  291.